/**
 * 录用列表
 */
import React from 'react';
import { Table } from 'antd';
import { TableFilter } from '@/components';
import { getDisplayText } from '@/utils/dataDictUtil';
import {
    renderHireStatus,
    renderHireRecordOperate,
    renderNameWithReadFlagTitle,
    renderNameWithReadFlag
} from '../renderUtil';
import { HIRE_STATUS, SEX } from '../dictionary';

const HireCommonTable = ({
    loading,
    dataSource,
    condition,
    onJumpDetail,
    onRefresh,
    sortOrders,
    isPrincipal,
    isLauncher,
    ...rest
}) => {
    const columns = [
        {
            title: renderNameWithReadFlagTitle('姓名'),
            dataIndex: 'readFlag',
            render: (value, record) => {
                const { talentName = '--', showReadFlag, hasBlackList } = record;
                return renderNameWithReadFlag(talentName, value, showReadFlag, hasBlackList);
            }
        },
        {
            title: '性别',
            dataIndex: 'talentSex',
            filteredValue: condition.talentSex ? [condition.talentSex] : [],
            filters: SEX,
            filterMultiple: false,
            filterDropdown: filterProps => <TableFilter {...filterProps} />,
            render: sex => getDisplayText(SEX, sex)
        },
        {
            title: '手机',
            dataIndex: 'talentPhone'
        },
        {
            title: '状态',
            dataIndex: 'employStatus',
            filteredValue: condition.employStatus ? [condition.employStatus] : [],
            filters: HIRE_STATUS,
            filterMultiple: false,
            onCell: () => ({
                onClick: e => {
                    e.stopPropagation();
                }
            }),
            filterDropdown: filterProps => <TableFilter {...filterProps} />,
            render: (val, record) => renderHireStatus(val, record.employStatusHover, record.talentEmployeeCode)
        },
        {
            title: '操作',
            dataIndex: 'action',
            onCell: () => ({
                onClick: e => {
                    e.stopPropagation();
                }
            }),
            render: (_, record) => renderHireRecordOperate(record, onRefresh, isPrincipal, isLauncher)
        }
    ];
    return (
        <>
            <Table
                {...rest}
                rowKey="employId"
                bordered={false}
                columns={columns}
                loading={loading}
                dataSource={dataSource}
                pagination={false}
                onRow={record => ({
                    onClick: () => {
                        const { recruitTalentMatcherId, employId, candidateId } = record;
                        if (onJumpDetail) onJumpDetail({ recruitTalentMatcherId, employId, candidateId });
                    }
                })}
            />
        </>
    );
};
export default HireCommonTable;
